<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>订单结算</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC_URL__/static/mobile/css/weui.css"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/mobile/css/index.css"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/mobile/mycord/css/cord.css" />
    <script src="__STATIC_URL__/static/mobile/js/weui.min.js" type="text/javascript" charset="utf-8"></script>
    <style>
a{
    color: #10aeff;
}
    </style>
</head>

<body>
<div class="container" id="container">
    <br>
    <br>
    <div class="weui-form-preview">
        <div class="weui-form-preview__hd">


            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">付款金额</label>
                <em class="weui-form-preview__value">¥{$cinfo['price']}</em>
            </div>
        </div>
        <div class="weui-form-preview__bd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">商品</label>
                <a href="{:url('cardshopnu/paycardsinfo',array('fid'=>$cinfo['fid'],'card_id'=>$card['card_id']))}">
                <span class="weui-form-preview__value">{$cinfo['Paycardinfo']['title']}</span>
                </a>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">订单编号</label>
                <span class="weui-form-preview__value">{$cinfo['orderid']}</span>
            </div>
        </div>
        <div class="weui-form-preview__hd">

        </div>
    </div>
    <div class="jine">

        <form action="" method="post">

            <div style="display:none;" id="qita">
                <input type="number" name="money" id="money" placeholder="充值金额(元)" min="0.1" max="9999" maxlength="4"/>

            </div>
            <ol class="weui-cells__title" type="1"  id="czshow">

            </ol>
            <a href="javascript:;" class="weui-btn weui-btn_primary">立即支付</a>
        </form>
    </div>

</div>


<!----->
<div id="dialogt">
    <div class="js_dialog" id="iosDialog3" style="opacity: 1; display: none;">
        <div class="weui-mask">
        </div>
        <div class="weui-dialog">
            <div class="weui-dialog__bd">
                <div class="bgfff chakan" >
                    <p class="ku"></p>
                </div>
            </div>
            <div class="weui-dialog__ft">

                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确认</a>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__STATIC_URL__/static/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" id="tpl_dialog">
    $(function(){
        var $iosDialog1 = $('#iosDialog1');
        var $iosDialog2 = $('#iosDialog2');
        $('#dialogs').on('click', '.weui-dialog__btn', function(){
            $(this).parents('.js_dialog').fadeOut(200);
        });
        $('#dialog').on('click', '.weui-dialog__btn', function(){
            $(this).parents('.js_dialog').fadeOut(200);
        });
        $('#dialogt').on('click', '.weui-dialog__btn', function(){
            $(this).parents('.js_dialog').fadeOut(200);
        });
        $('.showIOSDialog1').on('click', function(){
            $iosDialog1.fadeIn(200);
        });
        $('.showIOSDialog2').on('click', function(){
            $iosDialog2.fadeIn(200);
        });

        $(".cancel").click(function(){
            $(this).parent().attr("style","display:none");
        })
    });
</script>

<script type="text/javascript">
    $(function () {

        var paydata={$jsApiObj};

        $(".weui-btn_primary").click(function () {



                    if (typeof WeixinJSBridge == "undefined") {
                        if (document.addEventListener) {
                            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                        } else if (document.attachEvent) {
                            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                        }
                    } else {
                        onBridgeReady(paydata);
                    }



    })

    function onBridgeReady(sdata) {

        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', sdata,
            function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {

                    paysuccess();
                }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                else if(res.err_msg == "get_brand_wcpay_request:fail"){
                    onBridgeReady({$jsApiObj});
                }
            }
        );

    };

    function paysuccess() {


        $.ajax({
            type: "POST",

            url: "{:url('Cardshopnu/paysuccess')}",

            cache: false,
            dataType: "json",
            async: false,
            data: {
                id:"{$cinfo['mid']}",
                orderid:"{$cinfo['orderid']}",
                // cardid: $('#cardid').val(),
            },

            success: function (data) {

                console.log(data.data[0]);
                if (data.code == 0) {

                    $(".ku").html("支付成功！");
                    $("#iosDialog3").fadeIn(200);

                    var url=data.data.url;
                    setTimeout(function(){ window.location.replace(url); },400)

                } else {

                    $(".ku").html("支付失败！");
                    $("#iosDialog3").fadeIn(200);
                }
            }


        });}
    })

</script>
</html>